<style id="css_preset">
<?php echo $campaign['css_preset'] ?>
</style>

<?php
if ($is_admin == 1):
    ?>

    <div style="position:fixed;bottom:0;right:0">
        <a href="javascript:void(0)" class="btn btn-primary css_editor_luncher"><i class="icon-pencil"></i> Campaign CSS Editor</a>
    </div>

    <div id="campaign_css_editor" class="modal hide fade" style="width:800px;margin-left:-400px;">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h3>Campaign CSS Editor</h3>
        </div>
        <div class="modal-body">
            <p>
                <textarea id="css_preset_textarea"><?php echo $campaign['css_preset'] ?></textarea>
            </p>
        </div>
        <div class="modal-footer">
            <button class="btn btn-primary" id="save_css_preset" data-loading-text="Updating...">Save changes</button>
            <button class="btn btn-danger" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </div>

    <!-- Campaign CSS Editor -->
    <script>
        $(function() {
            editor = null;
            $("#campaign_css_editor").draggable({
                handle: ".modal-header"
            });
            $('.css_editor_luncher').click(function() {

                $(this).fadeOut();
                $('#campaign_css_editor').modal({
                    backdrop: false
                });
            });
            $('#campaign_css_editor').on('hidden', function() {
                $('.css_editor_luncher').fadeIn();
            });
            $('#campaign_css_editor').on('shown', function() {
                if (editor == null)
                {
                    editor = CodeMirror.fromTextArea(document.getElementById('css_preset_textarea'), {
                        mode: 'text/css',
                        tabMode: 'indent',
                        theme: 'ambiance',
                        autofocus: true,
                        smartIndent: true,
                        showCursorWhenSelecting: true
                    });

                    var delay;
                    editor.on("change", function() {
                        clearTimeout(delay);
                        delay = setTimeout(css_update, 300);
                    });

                }
            });

            function css_update()
            {
                $('#css_preset').html(editor.getValue());
                set_background();
            }
            $('#save_css_preset').click(function() {
                css_update();
                $('#save_css_preset').button('loading');
                $.post('<?php echo base_url() ?>ajax/do_update_css_preset', {hash: '<?php echo $hash ?>', sponsor_id: '<?php echo $campaign['sponsor_id'] ?>', 'css': editor.getValue()}, function() {
                    $('#save_css_preset').button('reset');
                    $('#campaign_css_editor').modal('hide')
                });
            });

        });
    </script>

    <?php
endif;
?>
<img class="sponsor-background"/>

<div class="row campaign-wrapper">
    <!-- Campaign Header -->
    <div class="span12">
        <div class="is-block bottom">
            <img src="<?php echo base_url() ?>timthumb.php?src=<?php echo base_url() ?>uploads/sponsor_logo/<?php echo $campaign['logo'] ?>" style="width:76px;height:76px;margin-right:10px;" class="img-polaroid img-rounded pull-left"/>
            <table class="<?php echo $campaign['css_class'] ?> table campaign-list-table" style="margin-bottom: 0;width:824px">
                <thead>
                    <tr>
                        <th colspan="2"><?php echo $campaign['title'] ?></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td colspan="2">
                            <?php
                            if ($campaign['status'] != 'pending') {
                                ?>
                                <a href="<?php echo base_url() ?>contest/<?php echo $hash ?>" class="btn <?php echo $this->uri->segment(3) == '' ? 'active' : '' ?>"><i class="icon-home"></i> หน้าผู้เข้าแข่งขัน</a>
                                <?php
                            }
                            ?>
                            <a href="<?php echo base_url() ?>contest/<?php echo $hash ?>/description" class="btn <?php echo $this->uri->segment(3) == 'description' ? 'active' : '' ?>"><i class="icon-book"></i> รายละเอียดกิจกรรมและของรางวัล</a>   

                            <?php
                            if ($campaign['status'] == 'starting') {
                                ?>
                                <a href="<?php echo base_url() ?>contest/<?php echo $hash ?>/register" class="btn <?php echo $this->uri->segment(3) == 'register' ? 'active' : '' ?>"><i class="icon-pencil"></i> ลงทะเบียน</a>
                                <?php
                            }
                            
                            if ($campaign['status'] != 'pending') {
                                ?>
                                <a href="<?php echo base_url() ?>contest/<?php echo $hash ?>/rank" class="btn <?php echo $this->uri->segment(3) == 'rank' ? 'active' : '' ?>"><i class="icon-bar-chart"></i> จัดอันดับ</a>
                                <?php
                            }
                            
                            if ($campaign['status'] == 'stopped')
                            {
                                ?>
                                <a href="<?php echo base_url() ?>contest/<?php echo $hash ?>/announcement" class="btn <?php echo $this->uri->segment(3) == 'announcement' ? 'active' : '' ?>"><i class="icon-bullhorn"></i> จัดอันดับ</a>
                                <?php
                            }
                            ?>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?php echo $campaign_content; ?>

